package springIOC.IOC_XML.controller;

import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import springIOC.IOC_XML.service.UserService;

import javax.annotation.Resource;

//@org.springframework.stereotype.Controller("controller")
//@Scope("prototype")
public class Controller {

//    @Autowired
//    @Qualifier("userService")
    @Resource(name="userService")
UserService service=null;
//    User user=null;

    public UserService getService() {
        return service;
    }

    public void setService(UserService service) {
        this.service = service;
    }

    public static void main(String[] args) {
//        Controller controller=new Controller();

        test1();
    }

    public static void test1(){
//        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("bean.xml");
//
//        Controller controller=(Controller)context.getBean("controller");
//
//        System.out.println(controller.getService());
//
//        System.out.println(controller.getService().findUserByID(1001));
//
//        System.out.println(controller.getService().findUserByName("jerry"));
//
//        System.out.println("------------------------------------------------");
//        System.out.println(controller.getService().getAccount().toString());
//
//        System.out.println("------------------------------------------------");
//        System.out.println(controller.getService().getBeanInfo().toString());
//        context.close();
    }

    /**
     * beanFactory采用的是懒加载
     */
//    public static void test2(){
//        Resource resource=new ClassPathResource("bean.xml");
//        BeanFactory factory=new XmlBeanFactory(resource);
//        Controller controller=factory.getBean("controller", Controller.class);
//
//        System.out.println(controller.getService());
//
//        System.out.println(controller.getService().findUserByID(10));
//
//        System.out.println("------------------------------------------------");
//        System.out.println(controller.getService().getAccount().toString());
//    }
}
